package utils

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// RespondJSON 封装通用 JSON 响应
func RespondJSON(c *gin.Context, status int, code string, message string, data interface{}) {
	c.JSON(status, gin.H{
		"code":    code,
		"message": message,
		"data":    data,
	})
}

// RespondSuccess 统一成功响应
func RespondSuccess(c *gin.Context, message string, data interface{}) {
	RespondJSON(c, http.StatusOK, "SUCCESS", message, data)
}

// RespondError 统一错误响应
func RespondError(c *gin.Context, status int, code string, message string, details interface{}) {
	c.JSON(status, gin.H{
		"code":    code,
		"message": message,
		"data":    gin.H{"details": details},
	})
}

// RespondBadRequest 400 错误响应
func RespondBadRequest(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusBadRequest, code, message, details)
}

// RespondNotFound 404 错误响应
func RespondNotFound(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusNotFound, code, message, details)
}

// RespondConflict 409 冲突响应
func RespondConflict(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusConflict, code, message, details)
}

// RespondInternalError 500 内部错误响应
func RespondInternalError(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusInternalServerError, code, message, details)
}

// RespondValidationError 验证错误响应
func RespondValidationError(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusBadRequest, code, message, details)
}

// RespondUnauthorized 401 未授权响应
func RespondUnauthorized(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusUnauthorized, code, message, details)
}

// RespondForbidden 403 禁止访问响应
func RespondForbidden(c *gin.Context, code string, message string, details interface{}) {
	RespondError(c, http.StatusForbidden, code, message, details)
}

// RespondWithSuggestion 带建议的错误响应
func RespondWithSuggestion(c *gin.Context, status int, code string, message string, details interface{}, suggestion string) {
	c.JSON(status, gin.H{
		"code":    code,
		"message": message,
		"data": gin.H{
			"details":    details,
			"suggestion": suggestion,
		},
	})
}
